package com.morehair.service.wx.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.morehair.bean.pojo.Brand;
import com.morehair.bean.pojo.BrandExample;
import com.morehair.bean.vo.wx.BrandVo;
import com.morehair.mapper.BrandMapper;
import com.morehair.service.wx.WxBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author  kkw
 * Date  2021/6/9 14:27
 * Version 1.0
 * Description :
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    BrandMapper brandMapper;

    @Override
    public Brand getBrandDetailById(Integer id) {
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        criteria.andDeletedEqualTo(false).andIdEqualTo(id);
        List<Brand> brands = brandMapper.selectByExample(brandExample);
        return brands.get(0);
    }

    @Override
    public BrandVo getBrandList(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        BrandExample brandExample = new BrandExample();
        brandExample.setOrderByClause("sort_order asc");
        BrandExample.Criteria criteria = brandExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<Brand> brandList = brandMapper.selectByExample(brandExample);

        PageInfo<Brand> brandPageInfo = new PageInfo<>(brandList);
        long total = brandPageInfo.getTotal();
        return new BrandVo((int) total,brandList);
    }
}
